#include <crypto/aes128.h>
#include <string.h>
#include <printf.h>
#include <util.h>

uint8_t kek[16] = {
	0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
	0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
};

uint8_t crypt[24] = {
	0x1F,0xA6,0x8B,0x0A,0x81,0x12,0xB4,0x47,
	0xAE,0xF3,0x4B,0xD8,0xFB,0x5A,0x7B,0x82,
	0x9D,0x3E,0x86,0x23,0x71,0xD2,0xCF,0xE5
};

uint8_t plain[24] = {
	0xA6,0xA6,0xA6,0xA6,0xA6,0xA6,0xA6,0xA6,
	0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
	0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF
};

static void compare(char* tag, uint8_t* got, uint8_t* exp, int nn)
{
	if(!memcmp(got, exp,nn))
		return;

	printf("FAIL %s\n", tag);
	_exit(0xFF);
}

int main(void)
{
	int nn = sizeof(crypt);
	uint8_t work[nn];

	memcpy(work, crypt, nn);
	aes128_unwrap(kek, work, nn);
	compare("unwrap", work, plain, nn);

	memcpy(work, plain, nn);
	aes128_wrap(kek, work, nn);
	compare("wrap", work, crypt, nn);

	return 0;
}
